
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      <link rel="icon" href="../../../../static/images/favicon.png">
      <meta name="generator" content="mkdocs-1.3.0, mkdocs-material-8.2.8">
    
    
      
        <title>一步一步将项目推送到maven中央仓库 - WL4G DOCS</title>
      
    
    
      <link rel="stylesheet" href="../../../../assets/stylesheets/main.644de097.min.css">
      
        
        <link rel="stylesheet" href="../../../../assets/stylesheets/palette.e6a45f82.min.css">
        
      
    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
      <link rel="stylesheet" href="../../../../static/css/util.css">
    
    <script>__md_scope=new URL("../../../..",location),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent="">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#maven" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
      <div data-md-component="outdated" hidden>
        <aside class="md-banner md-banner--warning">
          
        </aside>
      </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../../../.." title="WL4G DOCS" class="md-header__button md-logo" aria-label="WL4G DOCS" data-md-component="logo">
      
  <img src="../../../../static/images/mylogo.jpeg" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            WL4G DOCS
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              一步一步将项目推送到maven中央仓库
            
          </span>
        </div>
      </div>
    </div>
    
      <form class="md-header__option" data-md-component="palette">
        
          
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
          
            <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6zm0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4zM7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>
            </label>
          
        
          
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
          
            <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3z"/></svg>
            </label>
          
        
      </form>
    
    
      <div class="md-header__option">
        <div class="md-select">
          
          <button class="md-header__button md-icon" aria-label="Select language">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m12.87 15.07-2.54-2.51.03-.03A17.52 17.52 0 0 0 14.07 6H17V4h-7V2H8v2H1v2h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04M18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12m-2.62 7 1.62-4.33L19.12 17h-3.24z"/></svg>
          </button>
          <div class="md-select__inner">
            <ul class="md-select__list">
              
                <li class="md-select__item">
                  <a href="/en/" hreflang="en" class="md-select__link">
                    English
                  </a>
                </li>
                
                <li class="md-select__item">
                  <a href="/zh/" hreflang="zh" class="md-select__link">
                    简体中文
                  </a>
                </li>
                
            </ul>
          </div>
        </div>
      </div>
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
        </button>
      </nav>
      
        <div class="md-search__suggest" data-md-component="search-suggest"></div>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
            
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
  <div class="md-tabs__inner md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../../.." class="md-tabs__link">
        Getting Started
      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


  

<nav class="md-nav md-nav--primary md-nav--lifted md-nav--integrated" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../../../.." title="WL4G DOCS" class="md-nav__button md-logo" aria-label="WL4G DOCS" data-md-component="logo">
      
  <img src="../../../../static/images/mylogo.jpeg" alt="logo">

    </a>
    WL4G DOCS
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_1" data-md-state="indeterminate" type="checkbox" id="__nav_1" checked>
      
      
      
      
        <label class="md-nav__link" for="__nav_1">
          Getting Started
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Getting Started" data-md-level="1">
        <label class="md-nav__title" for="__nav_1">
          <span class="md-nav__icon md-icon"></span>
          Getting Started
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../../.." class="md-nav__link">
        Introduction
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../../../ABOUT_CN/" class="md-nav__link">
        About
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
          
          <div class="md-content" data-md-component="content">
            <article class="md-content__inner md-typeset">
              
                


<h1 id="maven">一步一步将项目推送到maven中央仓库<a class="headerlink" href="#maven" title="Permanent link">&para;</a></h1>
<p>最近工作比较空闲，做了一些实用小工具，在本地直接引用jar包实在是不方便，所以研究了一下如何将项目推送到maven中央仓库。怕日后遗忘，所以写这篇文章记录一下，也方便朋友们借鉴。</p>
<h2 id="_1">一、将代码上传到托管平台<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h2>
<p>这一步不必多说，想必大家都知道，git，码云，bitbucket都可以。</p>
<h2 id="sonatype">二、使用sonatype创建工单<a class="headerlink" href="#sonatype" title="Permanent link">&para;</a></h2>
<blockquote>
<p>非首次推送可忽略，同一groupId只有第一次较繁琐需提交工单，第二次之后推送无需再生成gpg秘钥了，直接到 <a href="四、推送到Maven中央仓库">第四步</a>。</p>
</blockquote>
<p>进入sonatype网站：<a href="https://issues.sonatype.org">https://issues.sonatype.org</a> 创建账号。</p>
<p>完成之后可以在页面顶部看到如下画面
<img alt="shot1" src="../img/shot1.jpg" /></p>
<p>项目选择：Community Support - Open Source Project Repository Hosting (OSSRH)</p>
<p>问题类型选择：New Project</p>
<p>概要：对要发布的项目作一个简单的描述。</p>
<p>描述选填可以不写。</p>
<p>group id：即将要发布的maven项目的group id。</p>
<p>Project Url：是项目所在地址。</p>
<p>SCM URL：clone项目的地址。</p>
<p>username(s)：就是你在该网站注册的用户名。</p>
<p>Already Synced to Centra：是否准备好同步到中央仓库，选择yes的话则会覆盖之前的构建。</p>
<p>填写完成后点击新建，然后等待审核。</p>
<p>如果你使用的是自己的域名，管理员会回复如下信息：
<img alt="shot2" src="../img/shot2.jpg" /></p>
<p>大意就是要使用他们提供的两种方式确认一下这个域名是属于你的。如果这个域名不是你拥有的，那么可以使用他们提供的域名作为group id。</p>
<p>我才用的是他们提供的第一种方法，就是在域名解析添加一条解析，记录类型为TXT，主机记录设为空，记录值是JIRA ticket。</p>
<p>然后回复他们：Yes, this domain is mine. 就ok了（英语不好，不会写太多，简单粗暴就行）。</p>
<p>很快他们就会回复审核通过。
<img alt="shot3" src="../img/shot3.jpg" /></p>
<h2 id="gpg">三、安装GPG<a class="headerlink" href="#gpg" title="Permanent link">&para;</a></h2>
<p>GPG下载地址：<a href="https://www.gnupg.org/download/index.html">https://www.gnupg.org/download/index.html</a></p>
<p>我是Mac，所以下载的GnuPG for OS X，下载下来安装，安装完成之后打开terminal</p>
<p>输入：<code>gpg2 --version</code> 可以查看GPG版本
<img alt="shot4" src="../img/shot4.jpg" /></p>
<p>输入：<code>gpg2 --gen-key</code> 创建密钥对。根据提示输入姓名和邮箱地址，这两个其实不重要，重要的是一定要记住Passphase，相当于你的密码。生成成功之后会显示你的公钥信息。如果没有找到也没事，可以通过输入： <code>gpg2 --list-keys</code> 来查询。</p>
<p>找到生成好的公钥后，输入：
<div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1"></a><a href="#__codelineno-0-1"><span class="linenos" data-linenos="1 "></span></a>gpg2 --keyserver hkp://pool.sks-keyservers.net:11371 --send-keys [你的公钥]   # 可填完整pubKey，但需注意实际上只上传了后缀一部分
</code></pre></div>
把公钥上传到服务器。</p>
<p><a href="https://central.sonatype.org/pages/working-with-pgp-signatures.html">参考推送gpg密钥sonatype文档</a></p>
<p>检查是否上传成功：
<div class="highlight"><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1"></a><a href="#__codelineno-1-1"><span class="linenos" data-linenos="1 "></span></a>gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys [你的公钥]   # 可填完整pubKey，但需注意实际上只上传了后缀一部分
</code></pre></div></p>
<blockquote>
<p>特别注意：此步骤非常重要，否则最后mvn deploy的时会校验不通过，亲测在mvn推送时可能会遇到总是No public key错误，可能是密钥服务器延迟的问题，目前也没有好办法，<code>gpg2 --list-key</code>查看生成的密钥找到库文件路径删掉，然后重新生成多试几次。</p>
</blockquote>
<p>在web上验证是否成功上传gpg密钥到验证服务：</br>
http://pool.sks-keyservers.net
<img alt="shot7" src="../img/shot7.jpg" /></p>
<blockquote>
<p>提示一下这里也有一个小坑需注意，搜索条件不能直接粘贴gpg生成的pubkey，需要以十六进制&nbsp; <code>0x</code> &nbsp;开头加上 pubkey的后16位字符，例如：
<div class="highlight"><pre><span></span><code><a id="__codelineno-2-1" name="__codelineno-2-1"></a><a href="#__codelineno-2-1"><span class="linenos" data-linenos="1 "></span></a>0x758F0F53778F6xxx
</code></pre></div>
<img alt="" src="../img/shot6.png" /></p>
</blockquote>
<h5 id="httppoolsks-keyserversnet">或在这里查：http://pool.sks-keyservers.net<a class="headerlink" href="#httppoolsks-keyserversnet" title="Permanent link">&para;</a></h5>
<p><img alt="查询" src="../img/view_gpg_upload1.png" /></p>
<h5 id="_2">查询结果：<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h5>
<p><img alt="查询结果" src="../img/view_gpg_upload2.png" /></p>
<blockquote>
<p>注：这里一定要能查到，后面才能deploy，否则会验证不成功。如果一次上传不行就多试几次，貌似我也是测试了几次才行，还有就是注意上传的地址协议开头 <code>"hkp://"</code>、<code>"hkps://"</code> 还是 <code>"http://"</code>、<code>"https://"</code>的区别，不行就更换尝试，如果网络连不上就换一个地址试试，如：keyserver.ubuntu.com，<code>万恶的中华局域网w(ﾟДﾟ)w</code></p>
<p>提示：Sonatype公司会用到三个key-servers，校验时会任意查其中一个，地址分别为：
http://pgp.mit.edu:11371</br>
http://keyserver.ubuntu.com:11371</br>
http://pool.sks-keyservers.net:11371</br></p>
</blockquote>
<h2 id="maven_1">三、配置Maven<a class="headerlink" href="#maven_1" title="Permanent link">&para;</a></h2>
<p>修改maven全局配置文件setting.xml，找到<servers></servers>，在里面添加如下信息：
<div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1"></a><a href="#__codelineno-3-1"><span class="linenos" data-linenos=" 1 "></span></a>    &lt;server&gt;
<a id="__codelineno-3-2" name="__codelineno-3-2"></a><a href="#__codelineno-3-2"><span class="linenos" data-linenos=" 2 "></span></a>        &lt;id&gt;sonatype-nexus-snapshots&lt;/id&gt;
<a id="__codelineno-3-3" name="__codelineno-3-3"></a><a href="#__codelineno-3-3"><span class="linenos" data-linenos=" 3 "></span></a>        &lt;username&gt;sonatype用户名&lt;/username&gt;
<a id="__codelineno-3-4" name="__codelineno-3-4"></a><a href="#__codelineno-3-4"><span class="linenos" data-linenos=" 4 "></span></a>        &lt;password&gt;sonatype密码&lt;/password&gt;
<a id="__codelineno-3-5" name="__codelineno-3-5"></a><a href="#__codelineno-3-5"><span class="linenos" data-linenos=" 5 "></span></a>    &lt;/server&gt;
<a id="__codelineno-3-6" name="__codelineno-3-6"></a><a href="#__codelineno-3-6"><span class="linenos" data-linenos=" 6 "></span></a>    &lt;server&gt;
<a id="__codelineno-3-7" name="__codelineno-3-7"></a><a href="#__codelineno-3-7"><span class="linenos" data-linenos=" 7 "></span></a>        &lt;id&gt;sonatype-nexus-staging&lt;/id&gt;
<a id="__codelineno-3-8" name="__codelineno-3-8"></a><a href="#__codelineno-3-8"><span class="linenos" data-linenos=" 8 "></span></a>        &lt;username&gt;sonatype用户名&lt;/username&gt;
<a id="__codelineno-3-9" name="__codelineno-3-9"></a><a href="#__codelineno-3-9"><span class="linenos" data-linenos=" 9 "></span></a>        &lt;password&gt;sonatype密码&lt;/password&gt;
<a id="__codelineno-3-10" name="__codelineno-3-10"></a><a href="#__codelineno-3-10"><span class="linenos" data-linenos="10 "></span></a>    &lt;/server&gt;
</code></pre></div>
将用户名和密码改成之前注册的sonatype的用户名密码就好了。</p>
<p>由于我安装的是GPG2所以要需要在下面修改一个地方，找到&lt;profiles&gt;&lt;/profiles&gt;，添加：
<div class="highlight"><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1"></a><a href="#__codelineno-4-1"><span class="linenos" data-linenos="1 "></span></a>    &lt;profile&gt;
<a id="__codelineno-4-2" name="__codelineno-4-2"></a><a href="#__codelineno-4-2"><span class="linenos" data-linenos="2 "></span></a>        &lt;id&gt;gpg&lt;/id&gt;
<a id="__codelineno-4-3" name="__codelineno-4-3"></a><a href="#__codelineno-4-3"><span class="linenos" data-linenos="3 "></span></a>        &lt;properties&gt;
<a id="__codelineno-4-4" name="__codelineno-4-4"></a><a href="#__codelineno-4-4"><span class="linenos" data-linenos="4 "></span></a>            &lt;gpg.executable&gt;gpg2&lt;/gpg.executable&gt;
<a id="__codelineno-4-5" name="__codelineno-4-5"></a><a href="#__codelineno-4-5"><span class="linenos" data-linenos="5 "></span></a>            &lt;gpg.passphrase&gt;mypassphrase&lt;/gpg.passphrase&gt;
<a id="__codelineno-4-6" name="__codelineno-4-6"></a><a href="#__codelineno-4-6"><span class="linenos" data-linenos="6 "></span></a>        &lt;/properties&gt;
<a id="__codelineno-4-7" name="__codelineno-4-7"></a><a href="#__codelineno-4-7"><span class="linenos" data-linenos="7 "></span></a>    &lt;/profile&gt;
</code></pre></div></p>
<p>找到&lt;activeProfiles&gt;&lt;/activeProfiles&gt;，添加：
 <div class="highlight"><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1"></a><a href="#__codelineno-5-1"><span class="linenos" data-linenos="1 "></span></a>    &lt;activeProfile&gt;gpg&lt;/activeProfile&gt;
</code></pre></div>
完成后保存退出。</p>
<p>在待上传的项目中的pom.xml中添加：
<div class="highlight"><pre><span></span><code><a id="__codelineno-6-1" name="__codelineno-6-1"></a><a href="#__codelineno-6-1"><span class="linenos" data-linenos=" 1 "></span></a>    &lt;licenses&gt;
<a id="__codelineno-6-2" name="__codelineno-6-2"></a><a href="#__codelineno-6-2"><span class="linenos" data-linenos=" 2 "></span></a>        &lt;license&gt;
<a id="__codelineno-6-3" name="__codelineno-6-3"></a><a href="#__codelineno-6-3"><span class="linenos" data-linenos=" 3 "></span></a>            &lt;name&gt;The Apache Software License, Version 2.0&lt;/name&gt;
<a id="__codelineno-6-4" name="__codelineno-6-4"></a><a href="#__codelineno-6-4"><span class="linenos" data-linenos=" 4 "></span></a>            &lt;url&gt;http://www.apache.org/licenses/LICENSE-2.0.txt&lt;/url&gt;
<a id="__codelineno-6-5" name="__codelineno-6-5"></a><a href="#__codelineno-6-5"><span class="linenos" data-linenos=" 5 "></span></a>        &lt;/license&gt;
<a id="__codelineno-6-6" name="__codelineno-6-6"></a><a href="#__codelineno-6-6"><span class="linenos" data-linenos=" 6 "></span></a>    &lt;/licenses&gt;
<a id="__codelineno-6-7" name="__codelineno-6-7"></a><a href="#__codelineno-6-7"><span class="linenos" data-linenos=" 7 "></span></a>    &lt;developers&gt;
<a id="__codelineno-6-8" name="__codelineno-6-8"></a><a href="#__codelineno-6-8"><span class="linenos" data-linenos=" 8 "></span></a>        &lt;developer&gt;
<a id="__codelineno-6-9" name="__codelineno-6-9"></a><a href="#__codelineno-6-9"><span class="linenos" data-linenos=" 9 "></span></a>            &lt;name&gt;开发者名&lt;/name&gt;
<a id="__codelineno-6-10" name="__codelineno-6-10"></a><a href="#__codelineno-6-10"><span class="linenos" data-linenos="10 "></span></a>            &lt;email&gt;开发者邮箱&lt;/email&gt;
<a id="__codelineno-6-11" name="__codelineno-6-11"></a><a href="#__codelineno-6-11"><span class="linenos" data-linenos="11 "></span></a>        &lt;/developer&gt;
<a id="__codelineno-6-12" name="__codelineno-6-12"></a><a href="#__codelineno-6-12"><span class="linenos" data-linenos="12 "></span></a>    &lt;/developers&gt;
<a id="__codelineno-6-13" name="__codelineno-6-13"></a><a href="#__codelineno-6-13"><span class="linenos" data-linenos="13 "></span></a>    &lt;scm&gt;
<a id="__codelineno-6-14" name="__codelineno-6-14"></a><a href="#__codelineno-6-14"><span class="linenos" data-linenos="14 "></span></a>        &lt;connection&gt;scm:项目的ssh地址&lt;/connection&gt;
<a id="__codelineno-6-15" name="__codelineno-6-15"></a><a href="#__codelineno-6-15"><span class="linenos" data-linenos="15 "></span></a>        &lt;developerConnection&gt;scm:项目的ssh地址&lt;/developerConnection&gt;
<a id="__codelineno-6-16" name="__codelineno-6-16"></a><a href="#__codelineno-6-16"><span class="linenos" data-linenos="16 "></span></a>        &lt;url&gt;项目地址&lt;/url&gt;
<a id="__codelineno-6-17" name="__codelineno-6-17"></a><a href="#__codelineno-6-17"><span class="linenos" data-linenos="17 "></span></a>    &lt;/scm&gt;
<a id="__codelineno-6-18" name="__codelineno-6-18"></a><a href="#__codelineno-6-18"><span class="linenos" data-linenos="18 "></span></a>    &lt;profiles&gt;
<a id="__codelineno-6-19" name="__codelineno-6-19"></a><a href="#__codelineno-6-19"><span class="linenos" data-linenos="19 "></span></a>        &lt;profile&gt;
<a id="__codelineno-6-20" name="__codelineno-6-20"></a><a href="#__codelineno-6-20"><span class="linenos" data-linenos="20 "></span></a>            &lt;id&gt;release&lt;/id&gt;
<a id="__codelineno-6-21" name="__codelineno-6-21"></a><a href="#__codelineno-6-21"><span class="linenos" data-linenos="21 "></span></a>            &lt;build&gt;
<a id="__codelineno-6-22" name="__codelineno-6-22"></a><a href="#__codelineno-6-22"><span class="linenos" data-linenos="22 "></span></a>                &lt;plugins&gt;
<a id="__codelineno-6-23" name="__codelineno-6-23"></a><a href="#__codelineno-6-23"><span class="linenos" data-linenos="23 "></span></a>                    &lt;!-- Source --&gt;
<a id="__codelineno-6-24" name="__codelineno-6-24"></a><a href="#__codelineno-6-24"><span class="linenos" data-linenos="24 "></span></a>                    &lt;plugin&gt;
<a id="__codelineno-6-25" name="__codelineno-6-25"></a><a href="#__codelineno-6-25"><span class="linenos" data-linenos="25 "></span></a>                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
<a id="__codelineno-6-26" name="__codelineno-6-26"></a><a href="#__codelineno-6-26"><span class="linenos" data-linenos="26 "></span></a>                        &lt;artifactId&gt;maven-source-plugin&lt;/artifactId&gt;
<a id="__codelineno-6-27" name="__codelineno-6-27"></a><a href="#__codelineno-6-27"><span class="linenos" data-linenos="27 "></span></a>                        &lt;executions&gt;
<a id="__codelineno-6-28" name="__codelineno-6-28"></a><a href="#__codelineno-6-28"><span class="linenos" data-linenos="28 "></span></a>                            &lt;execution&gt;
<a id="__codelineno-6-29" name="__codelineno-6-29"></a><a href="#__codelineno-6-29"><span class="linenos" data-linenos="29 "></span></a>                                &lt;phase&gt;package&lt;/phase&gt;
<a id="__codelineno-6-30" name="__codelineno-6-30"></a><a href="#__codelineno-6-30"><span class="linenos" data-linenos="30 "></span></a>                                &lt;goals&gt;
<a id="__codelineno-6-31" name="__codelineno-6-31"></a><a href="#__codelineno-6-31"><span class="linenos" data-linenos="31 "></span></a>                                    &lt;goal&gt;jar-no-fork&lt;/goal&gt;
<a id="__codelineno-6-32" name="__codelineno-6-32"></a><a href="#__codelineno-6-32"><span class="linenos" data-linenos="32 "></span></a>                                &lt;/goals&gt;
<a id="__codelineno-6-33" name="__codelineno-6-33"></a><a href="#__codelineno-6-33"><span class="linenos" data-linenos="33 "></span></a>                            &lt;/execution&gt;
<a id="__codelineno-6-34" name="__codelineno-6-34"></a><a href="#__codelineno-6-34"><span class="linenos" data-linenos="34 "></span></a>                        &lt;/executions&gt;
<a id="__codelineno-6-35" name="__codelineno-6-35"></a><a href="#__codelineno-6-35"><span class="linenos" data-linenos="35 "></span></a>                    &lt;/plugin&gt;
<a id="__codelineno-6-36" name="__codelineno-6-36"></a><a href="#__codelineno-6-36"><span class="linenos" data-linenos="36 "></span></a>                    &lt;!-- Javadoc --&gt;
<a id="__codelineno-6-37" name="__codelineno-6-37"></a><a href="#__codelineno-6-37"><span class="linenos" data-linenos="37 "></span></a>                    &lt;plugin&gt;
<a id="__codelineno-6-38" name="__codelineno-6-38"></a><a href="#__codelineno-6-38"><span class="linenos" data-linenos="38 "></span></a>                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
<a id="__codelineno-6-39" name="__codelineno-6-39"></a><a href="#__codelineno-6-39"><span class="linenos" data-linenos="39 "></span></a>                        &lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
<a id="__codelineno-6-40" name="__codelineno-6-40"></a><a href="#__codelineno-6-40"><span class="linenos" data-linenos="40 "></span></a>                        &lt;executions&gt;
<a id="__codelineno-6-41" name="__codelineno-6-41"></a><a href="#__codelineno-6-41"><span class="linenos" data-linenos="41 "></span></a>                            &lt;execution&gt;
<a id="__codelineno-6-42" name="__codelineno-6-42"></a><a href="#__codelineno-6-42"><span class="linenos" data-linenos="42 "></span></a>                                &lt;phase&gt;package&lt;/phase&gt;
<a id="__codelineno-6-43" name="__codelineno-6-43"></a><a href="#__codelineno-6-43"><span class="linenos" data-linenos="43 "></span></a>                                &lt;goals&gt;
<a id="__codelineno-6-44" name="__codelineno-6-44"></a><a href="#__codelineno-6-44"><span class="linenos" data-linenos="44 "></span></a>                                    &lt;goal&gt;jar&lt;/goal&gt;
<a id="__codelineno-6-45" name="__codelineno-6-45"></a><a href="#__codelineno-6-45"><span class="linenos" data-linenos="45 "></span></a>                                &lt;/goals&gt;
<a id="__codelineno-6-46" name="__codelineno-6-46"></a><a href="#__codelineno-6-46"><span class="linenos" data-linenos="46 "></span></a>                            &lt;/execution&gt;
<a id="__codelineno-6-47" name="__codelineno-6-47"></a><a href="#__codelineno-6-47"><span class="linenos" data-linenos="47 "></span></a>                        &lt;/executions&gt;
<a id="__codelineno-6-48" name="__codelineno-6-48"></a><a href="#__codelineno-6-48"><span class="linenos" data-linenos="48 "></span></a>                    &lt;/plugin&gt;
<a id="__codelineno-6-49" name="__codelineno-6-49"></a><a href="#__codelineno-6-49"><span class="linenos" data-linenos="49 "></span></a>                    &lt;!-- GPG --&gt;
<a id="__codelineno-6-50" name="__codelineno-6-50"></a><a href="#__codelineno-6-50"><span class="linenos" data-linenos="50 "></span></a>                    &lt;plugin&gt;
<a id="__codelineno-6-51" name="__codelineno-6-51"></a><a href="#__codelineno-6-51"><span class="linenos" data-linenos="51 "></span></a>                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
<a id="__codelineno-6-52" name="__codelineno-6-52"></a><a href="#__codelineno-6-52"><span class="linenos" data-linenos="52 "></span></a>                        &lt;artifactId&gt;maven-gpg-plugin&lt;/artifactId&gt;
<a id="__codelineno-6-53" name="__codelineno-6-53"></a><a href="#__codelineno-6-53"><span class="linenos" data-linenos="53 "></span></a>                        &lt;version&gt;1.6&lt;/version&gt;
<a id="__codelineno-6-54" name="__codelineno-6-54"></a><a href="#__codelineno-6-54"><span class="linenos" data-linenos="54 "></span></a>                        &lt;executions&gt;
<a id="__codelineno-6-55" name="__codelineno-6-55"></a><a href="#__codelineno-6-55"><span class="linenos" data-linenos="55 "></span></a>                            &lt;execution&gt;
<a id="__codelineno-6-56" name="__codelineno-6-56"></a><a href="#__codelineno-6-56"><span class="linenos" data-linenos="56 "></span></a>                                &lt;phase&gt;verify&lt;/phase&gt;
<a id="__codelineno-6-57" name="__codelineno-6-57"></a><a href="#__codelineno-6-57"><span class="linenos" data-linenos="57 "></span></a>                                &lt;goals&gt;
<a id="__codelineno-6-58" name="__codelineno-6-58"></a><a href="#__codelineno-6-58"><span class="linenos" data-linenos="58 "></span></a>                                    &lt;goal&gt;sign&lt;/goal&gt;
<a id="__codelineno-6-59" name="__codelineno-6-59"></a><a href="#__codelineno-6-59"><span class="linenos" data-linenos="59 "></span></a>                                &lt;/goals&gt;
<a id="__codelineno-6-60" name="__codelineno-6-60"></a><a href="#__codelineno-6-60"><span class="linenos" data-linenos="60 "></span></a>                            &lt;/execution&gt;
<a id="__codelineno-6-61" name="__codelineno-6-61"></a><a href="#__codelineno-6-61"><span class="linenos" data-linenos="61 "></span></a>                        &lt;/executions&gt;
<a id="__codelineno-6-62" name="__codelineno-6-62"></a><a href="#__codelineno-6-62"><span class="linenos" data-linenos="62 "></span></a>                    &lt;/plugin&gt;
<a id="__codelineno-6-63" name="__codelineno-6-63"></a><a href="#__codelineno-6-63"><span class="linenos" data-linenos="63 "></span></a>                &lt;/plugins&gt;
<a id="__codelineno-6-64" name="__codelineno-6-64"></a><a href="#__codelineno-6-64"><span class="linenos" data-linenos="64 "></span></a>            &lt;/build&gt;
<a id="__codelineno-6-65" name="__codelineno-6-65"></a><a href="#__codelineno-6-65"><span class="linenos" data-linenos="65 "></span></a>            &lt;distributionManagement&gt;
<a id="__codelineno-6-66" name="__codelineno-6-66"></a><a href="#__codelineno-6-66"><span class="linenos" data-linenos="66 "></span></a>                &lt;snapshotRepository&gt;
<a id="__codelineno-6-67" name="__codelineno-6-67"></a><a href="#__codelineno-6-67"><span class="linenos" data-linenos="67 "></span></a>                    &lt;id&gt;sonatype-nexus-snapshots&lt;/id&gt;
<a id="__codelineno-6-68" name="__codelineno-6-68"></a><a href="#__codelineno-6-68"><span class="linenos" data-linenos="68 "></span></a>                    &lt;url&gt;https://oss.sonatype.org/content/repositories/snapshots/&lt;/url&gt;
<a id="__codelineno-6-69" name="__codelineno-6-69"></a><a href="#__codelineno-6-69"><span class="linenos" data-linenos="69 "></span></a>                &lt;/snapshotRepository&gt;
<a id="__codelineno-6-70" name="__codelineno-6-70"></a><a href="#__codelineno-6-70"><span class="linenos" data-linenos="70 "></span></a>                &lt;repository&gt;
<a id="__codelineno-6-71" name="__codelineno-6-71"></a><a href="#__codelineno-6-71"><span class="linenos" data-linenos="71 "></span></a>                    &lt;id&gt;sonatype-nexus-staging&lt;/id&gt;
<a id="__codelineno-6-72" name="__codelineno-6-72"></a><a href="#__codelineno-6-72"><span class="linenos" data-linenos="72 "></span></a>                    &lt;url&gt;https://oss.sonatype.org/service/local/staging/deploy/maven2/&lt;/url&gt;
<a id="__codelineno-6-73" name="__codelineno-6-73"></a><a href="#__codelineno-6-73"><span class="linenos" data-linenos="73 "></span></a>                &lt;/repository&gt;
<a id="__codelineno-6-74" name="__codelineno-6-74"></a><a href="#__codelineno-6-74"><span class="linenos" data-linenos="74 "></span></a>            &lt;/distributionManagement&gt;
<a id="__codelineno-6-75" name="__codelineno-6-75"></a><a href="#__codelineno-6-75"><span class="linenos" data-linenos="75 "></span></a>        &lt;/profile&gt;
<a id="__codelineno-6-76" name="__codelineno-6-76"></a><a href="#__codelineno-6-76"><span class="linenos" data-linenos="76 "></span></a>    &lt;/profiles&gt;
</code></pre></div>
将上面配置中的汉字内容替换为对应的信息就完成了。</p>
<h2 id="maven_2">四、推送到Maven中央仓库<a class="headerlink" href="#maven_2" title="Permanent link">&para;</a></h2>
<p>大功告成，可以通过deploy推送了使用下面代码推送到maven中央仓库：</p>
<p><div class="highlight"><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1"></a><a href="#__codelineno-7-1"><span class="linenos" data-linenos="1 "></span></a>mvn clean deploy -P release
</code></pre></div>
看到显示BUILD SUCCESS后就可以愉快的到中央仓库（<a href="https://oss.sonatype.org"><code>https://oss.sonatype.org</code></a>，使用sonatype账号登陆 -&gt; 左边点击 Staging Repositories），找发布的项目了。</p>
<p>当然前提是sonatype中创建的工单要审核通过，如果审核还没有通过是发布不了的，项目会在Staging Repositories菜单里。等审核通过后你需要选择你的项目，然后先点击close，顺利close之后（也就是在activity标签中没有报错信息，并且项目对应的status变为closed），再点一下release，等待release结束之后就完成了。</p>
<h2 id="_3">五、最后别忘了通知管理员关闭工单<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h2>
<p>在之前的工单下面添加一条备注，我写的：This Component has been successfully released, thank you.（也不知道有没有语病）。等管理员审核通过关闭了这个工单就算彻底完成了。</p>
<p>是不是很麻烦？没关系，只有第一次会这么麻烦，今后只要group id没有发生变化就可以直接推送，不需要在做这些繁琐的工作了。</p>
<p>附maven仓库搜索地址：https://search.maven.org/，以上工序都完成后可以在这个地址搜到自己推送的组件。</p>

              
            </article>
          </div>
        </div>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    <script id="__config" type="application/json">{"base": "../../../..", "features": ["search.suggest", "search.highlight", "navigation.tabs", "navigation.expand", "toc.follow", "toc.integrate"], "search": "../../../../assets/javascripts/workers/search.5e67fbfe.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version.title": "Select version"}, "version": {"default": "latest", "provider": "mike"}}</script>
    
    
      <script src="../../../../assets/javascripts/bundle.c44cc438.min.js"></script>
      
        <script src="../../../../static/js/util.js"></script>
      
    
  </body>
</html>